<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

//
$config = array(
		//
		'cname' => 'item',
		
		//
		'class_file' => 'module/resource/resource.class.php',
		'class_name' => 'ResourceBase',
		'class_param' => array('_table_status_usable' => false),
		
		//
		'inject' => array(
				'categories_options' => array(
									'type' => 'cm',
									'class_file' => 'module/resource/resource.category.class.php', 
									'class_name' => 'ResourceCategoryBase',
									'method' => 'getCategoriesFormat',
									'params' => array('', 0, false),
										),
					),
		
		//
		'tpl_type' => 'admin',
		'tpl_file' => 'pagelayout/pagelayout_admin_resource.tpl',
		
		//
		'validate_file' => '',
		'validate_class' => 'CommonValidate',
		'validate_fields' => array('field' => 'name', 'valid' => 'null'),
			);

//
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'control/item.control.class.php');
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'control/item.content.control.class.php');

//
class _ControlItemContentBase extends ControlItemContentBase {
	
	//constructor
	function _ControlItemContentBase($config = '') {
		parent::ControlItemContentBase($config);
		
		//
		if( $this->feObj->operation == 'X' ) {
			$this->actionHandler = 'doXActionHandler';
		}
		//
		if( $this->feObj->operation == 'detail' ) {
			$this->displayHandler = 'doDetailDisplayHandler';
		} elseif( in_array($this->feObj->operation, array('list-album', 'list-text')) ) {
			$this->displayHandler = 'doListDisplayHandler';
		}
	}
	
	//methods
	function doActionHandler() {
		echo 'doActionHandler';
		exit;
	}
	
	function doXActionHandler($obj) {
		
		_dms(':admin:success');
		$this->_redirect('', array('op'), 's');
	}
	
	//
	function doDisplayHandler() {
		echo 'doDisplayHandler';
		exit;
	}
	
	function doDetailDisplayHandler($obj) {
		$id = $this->feObj->_request['id'];
		if( $id > 0 ) {
			$item = $this->modelObj->getItem($id, 'id', -1);
			
			$this->feObj->content_wrap['mainpart'] = 'detail';
			$this->feObj->content_wrap['item'] = $item;
		} else {
			$this->_redirect('', array('op'), '');
		}
	}
	
	function doListDisplayHandler($obj) {
		$navigation = array();
		$limit = true;
		if( $this->feObj->_request['cid'] > 0 && $this->feObj->_request['nolimit'] == '1' ) {
			$limit = false;
		}
		$check = -1;
		if( $this->feObj->_request['check'] == '1' ) {
			$check = 0;
		}
		
		//
		if( $this->feObj->_request['cid'] > 0 ) {
			$filter = $this->_get_items_filter();
			$items = $this->modelObj->getItems($filter, $check, $limit);
		} else {
			$filter = $this->_get_items_filter();
			$limit_length = $this->feObj->limit_length;
			$limit_start = ($this->feObj->limit_page - 1) * $limit_length;
			$limit_total = $this->modelObj->getItemsTotal($filter, -1);
			//
			$this->modelObj->setQueryLimitStart($limit_start);
			$this->modelObj->setQueryLimitLength($limit_length);
			$items = $this->modelObj->getItems($filter, $check, $limit);
			//
			$parameters = util_get_all_get_params(array('page'));
			$link_array = array(
						'page' => '',
						'parameters' => $parameters,
							);
			$navigation = util_common_navigation($link_array, $limit_total, $limit_start, $limit_length);
		}
		
		//
		if( $this->feObj->operation == 'list-album' ) {
			$mainpart = 'listitem-album';
		} elseif( $this->feObj->operation == 'list-text' ) {
			$mainpart = 'listitem-text';
		}
		
		//
		$this->feObj->content_wrap['mainpart'] = $mainpart;
		$this->feObj->content_wrap['items'] = $items;
		$this->feObj->content_wrap['navigation'] = $navigation;
	}
	
	//
	function _doAfter() {
		
	}
}

//
$cntlObj = new _ControlItemContentBase($config);
$cntlObj->process();
//
?>